package com.tg.app.activity.base;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.ClipData;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.net.http.SslError;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.provider.MediaStore;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.view.WindowManager;
import android.webkit.CookieManager;
import android.webkit.JavascriptInterface;
import android.webkit.JsPromptResult;
import android.webkit.JsResult;
import android.webkit.SslErrorHandler;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.appbase.custom.constant.CommonConstants;
import com.base.BaseActivity;
import com.hjq.permissions.Permission;
import com.hjq.permissions.XXPermissions;
import com.tange.base.toolkit.AppUtil;
import com.tange.base.toolkit.PreferenceUtil;
import com.tange.base.toolkit.StringUtils;
import com.tange.core.backend.service.http.HttpConfigurations;
import com.tg.app.BuildConfig;
import com.tg.app.R;
import com.tg.app.activity.device.DeviceListActivity;
import com.tg.app.activity.device.add.ResetDeviceActivity;
import com.tg.app.helper.ActivityHelper;
import com.tg.appcommon.android.GetSystemMsgUtil;
import com.tg.appcommon.android.LanguageUtils;
import com.tg.appcommon.android.PermissionUtil;
import com.tg.appcommon.android.TGLog;
import com.tg.data.bean.DeviceSettingsInfo;
import com.tg.loginex.helper.LoginHelper;

import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.Map;

/**
 * Describe:
 * Created by Rance Rang on 2020-03-13.
 * <p>
 * Copyright (c) Tange.Inc All rights reserved.
 */
public class WebBaseActivity extends BaseActivity {
    private static final String TAG = "WebBaseActivity";
    protected boolean isPayRedirectUrl = false;
    protected WebView mWebview;
    protected String mWebUrl;
    private boolean isUninstallWechat = false;//没有安装微信
    private final String wepaySign = "https://payapp.weixin.qq.com/papay";
    private boolean isWepaySign = false;
    protected String redirecUrl = "";
    public static final String KEY_WEBTITLE = "key_title";
    public static final String KEY_WEBURL = "key_weburl";

    private boolean hasJsSetTitle = false;

    private final Handler mainHandler = new Handler(Looper.getMainLooper());

    private final String alipayUrl = "alipays://platformapi/startApp?";
    private final String payssion = "www.payssion.com";
    private final String weipayUrl = "weixin://";
    private final String intentUrl = "intent://";
    protected TextView tvTitle;
    private final int FILE_CHOOSER_RESULT_CODE =10;
    private  ValueCallback mValueCallback;
    protected DeviceSettingsInfo info;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
    }

    @Override
    public void initView() {

    }

    public void removeView(){
        TGLog.d(TAG, "removeView");
        mWebview.stopLoading();
        mWebview.pauseTimers();
        ViewParent parent = mWebview.getParent();
        if (parent != null) {
            ((ViewGroup) parent).removeView(mWebview);
        }
        if (mWebview != null){
            mWebview.destroy();
            mWebview = null;
        }
    }


    protected void updateStatusBarTextColor(boolean dark) {
    }

    protected int getContentMarginTop() {
        return 0;
    }

    protected void updateStatusBarColor(String colorStr) {

    }

    protected void updateToolBarTextColor(String colorStr) {

    }

    protected void updateToolBarBackgroundColor(String colorStr) {
    }

    protected void updateBackBtnColor(boolean useWhite) {
    }

    protected void setContentFullScreen(boolean fullScreen) {
    }

    private boolean getFile(ValueCallback valueCallback){
        TGLog.i(TAG, "webveiw valueCallback: " + valueCallback);
        if (!XXPermissions.isGranted(this, Permission.WRITE_EXTERNAL_STORAGE)) {
            String title =getString(com.module.appcommon.R.string.no_storage_permission_to_finish);
            String content = getString(com.module.appcommon.R.string.enable_permission_storage);
            PermissionUtil permissionUtil = new PermissionUtil(this);
            permissionUtil.checkPermissionFirst(Permission.WRITE_EXTERNAL_STORAGE, () -> {

            }, title, content);

            TGLog.i(TAG, "webveiw getfile: no permission");
            return false;
        }
        mValueCallback = valueCallback;
        @SuppressLint("IntentReset") Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
        intent.setType("video/mp4,image/*");
        startActivityForResult(intent, FILE_CHOOSER_RESULT_CODE);
        return true;
    }

    @Override
    public boolean shouldSetStatusBarColor() {
        return true;
    }

    public void initWeb() {
        WebSettings webSettings = mWebview.getSettings();
        webSettings.setJavaScriptEnabled(true);
        // 设置可以访问文件
        webSettings.setAllowFileAccess(true);
        // 设置支持缩放
        webSettings.setBuiltInZoomControls(true);
        webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
        // webSettings.setDatabaseEnabled(true);
        // 使用localStorage则必须打开
        webSettings.setUseWideViewPort(true); // 支持html设置viewport
        webSettings.setLoadWithOverviewMode(true); // body宽度超出自动缩放
        webSettings.setDomStorageEnabled(true);
        webSettings.setGeolocationEnabled(true);
        webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
        WebView.setWebContentsDebuggingEnabled(BuildConfig.DEBUG);
        webSettings.setPluginState(WebSettings.PluginState.ON_DEMAND);
        mWebview.setLayerType(View.LAYER_TYPE_HARDWARE,null);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
            CookieManager.getInstance().setAcceptThirdPartyCookies(mWebview, true);
        }
        mWebview.setWebChromeClient(new WebChromeClient(){
            // 3.0 + 调用这个方法
            public void openFileChooser(ValueCallback filePathCallback, String acceptType) {
                getFile(filePathCallback);
            }

            // Android > 4.1.1 调用这个方法
            public void openFileChooser(ValueCallback<Uri> filePathCallback, String acceptType, String capture) {
                getFile(filePathCallback);
            }

            // Android > 5.0 调用这个方法
            @Override
            public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, FileChooserParams fileChooserParams) {
                return  getFile(filePathCallback);
            }

            @Override
            public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
                TGLog.d(TAG,"onJsAlert : url = " + url + ", message = " + message);
                return false;
            }
            @Override
            public boolean onJsPrompt(WebView view, String url, String message,
                                      String defaultValue, JsPromptResult result) {
                TGLog.d(TAG,"onJsPrompt : url = " + url + ", message = " + message);
                return false;
            }

            @Override
            public void onConsoleMessage(String message, int lineNumber, String sourceID) {
                TGLog.d(TAG,"onConsoleMessage : message = " + message + ", sourceID = " + sourceID);
            }

            @Override
            public void onReceivedTitle(WebView view, String title) {
                super.onReceivedTitle(view, title);
                TGLog.d(TAG,"onReceivedTitle : === title = " + title);

            }
        });
        mWebview.setWebViewClient(new WebViewClient() {

            @Override
            public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error){
                TGLog.i(TAG, "onReceivedSslError errorCode = " + error.toString());
            }
            @Override
            public void onReceivedError(WebView view, int errorCode, String description, String failingUrl){
                TGLog.i(TAG, "onReceivedError errorCode = " + errorCode + "，description = " + description + "， failingUrl = " + failingUrl);
            }
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                TGLog.i(TAG, "shouldOverrideUrlLoading url = " + url);
                String payRedirect = "service/pay_redirect";
                clearHistory(url);
                if (url.contains(payRedirect)) {
                    isPayRedirectUrl = true;
                    TGLog.i(TAG, "isPayRedirectUrl 1");
                }
                if (url.toLowerCase().contains(alipayUrl.toLowerCase()) || url.toLowerCase().contains(weipayUrl.toLowerCase())) {
                    if (url.toLowerCase().contains(alipayUrl.toLowerCase()) && AppUtil.checkAliPayInstalled(getBaseContext())) {
                        return super.shouldOverrideUrlLoading(view, url);
                    }
                    if (url.toLowerCase().contains(weipayUrl.toLowerCase()) && !AppUtil.checkWeiXinInstalled(getBaseContext())) {
                        Toast.makeText(getBaseContext(), R.string.uninstall_wechat, Toast.LENGTH_LONG).show();
                        isUninstallWechat = true;
                        view.goBack();
                        return false;
                    }
                    payAction(url);
                    view.goBack();
                    return false;
                } else if (url.toLowerCase().contains(wepaySign.toLowerCase())) {
                    Map<String, String> webviewHead = new HashMap<>();
                    webviewHead.put("Referer", "http://tange365.com");
                    Uri uri = Uri.parse(url);
                    redirecUrl = uri.getQueryParameter("redirect_url");
                    mWebview.loadUrl(url, webviewHead);
                    return false;
                } else if (StringUtils.isDownloadUrl(url)){ //如果是下载apk或intent://开头，跳到浏览器下载
                    Uri uri = Uri.parse(url);
                    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                    startActivity(intent);
                    return false;
                }else if (url.toLowerCase().startsWith(intentUrl)){
                    return  intentSchme(view,url);
                }
                return super.shouldOverrideUrlLoading(view, url);
            }

            @Override
            public void onPageFinished(WebView view, String url) {
                if (!isUninstallWechat) {
                    super.onPageFinished(view, url);
                    if (url.toLowerCase().contains(wepaySign.toLowerCase())) {
                        if (isWepaySign) {
                            getOpenLink();
                        }
                        isWepaySign = true;
                    } else {
                        isWepaySign = false;
                    }
                }

                if (isUninstallWechat ) {
                    view.clearHistory();
                }
                clearHistory(url);

                String title = view.getTitle();
                TGLog.i(TAG, "onPageFinished url  :%s， title = %s", url, title);
                mainHandler.postDelayed(() -> {
                    if (tvTitle!=null && !TextUtils.isEmpty(title) && !StringUtils.equalsIgnoreCase("about:blank", title) && !hasJsSetTitle) {
                        TGLog.i(TAG, "===== title = %s", title);
                        if (!StringUtils.equals(title, "Privacy strategy")){
                            tvTitle.setText(title);
                        }

                    }
                }, 1000);
                if (url.toLowerCase().startsWith(intentUrl)){
                    intentSchme(view,url);
                }
            }

        });

        String token = PreferenceUtil.getString(this, CommonConstants.PRE_TOKEN);
        TGLog.i(TAG, "web token : "+token);
        mWebview.addJavascriptInterface(new SimService(this), "android");
        HttpConfigurations.getInstance().setLanguage(LanguageUtils.getLanguage(this));
        Uri.Builder builder = HttpConfigurations.getInstance().builderWithQueryParameter(mWebUrl,token);
        mWebUrl =  builder.toString();
        mWebUrl =  uriBuilderToString(builder);

        // 把所有的 // , 替换为 /
//        mWebUrl = mWebUrl.replace("//", "/");
        // 然后把替换掉的http前缀头双斜杠补回来
        mWebUrl = mWebUrl.replace("https:/", "https://");
        mWebUrl = mWebUrl.replace("http:/", "http://");

        mWebview.loadUrl(mWebUrl);
        TGLog.i(TAG, "mWebUrl : "+mWebUrl);
    }

    private boolean intentSchme(WebView view, String url) {
        Uri parsedUri = Uri.parse(url);
        PackageManager packageManager = getPackageManager();
        Intent browseIntent = new Intent(Intent.ACTION_VIEW).setData(parsedUri);
        if (browseIntent.resolveActivity(packageManager) != null) {
            startActivity(browseIntent);
//            return true;
        }

        //if not activity found, try to parse intent://
        if (url.startsWith("intent:")) {
            try {
                Intent intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME);
                if (intent.resolveActivity(packageManager) != null) {
                    startActivity(intent);
                    return true;
                }

                //try to find fallback url
                String fallbackUrl = intent.getStringExtra("browser_fallback_url");
                if (fallbackUrl != null) {
                    view.loadUrl(fallbackUrl);
                    return true;
                }

                //invite to install
                Intent marketIntent = new Intent(Intent.ACTION_VIEW).setData(
                        Uri.parse("market://details?id=" + intent.getPackage()));
                if (marketIntent.resolveActivity(packageManager) != null) {
                    startActivity(marketIntent);
                    return true;
                }
            } catch (URISyntaxException e) {
                Log.e("Payssion", "e:" + e.toString());
            }
        }
        return false;
    }

    protected String uriBuilderToString(Uri.Builder builder){
        Uri url = builder.build();
        String urlString = url.toString();
        if (!TextUtils.isEmpty(url.getEncodedFragment())){
            String fragment = "#"+url.getEncodedFragment();
            urlString = urlString.replace(fragment,"");
            if (fragment.contains("?")){
                fragment = fragment.concat("&");
            }else {
                fragment = fragment.concat("?");
            }
            urlString = urlString.replace("?",fragment);
        }
      return  urlString;
    }
    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode != FILE_CHOOSER_RESULT_CODE||mValueCallback==null||resultCode!=RESULT_OK){
            if (mValueCallback!=null){
                mValueCallback.onReceiveValue(null);
                mValueCallback = null;
            }
            return;
        }
        seleteH5File(data,mValueCallback);
    }

    public static void seleteH5File(Intent data, ValueCallback valueCallback){
        if (valueCallback == null){
            // todo valueCallback 为空的逻辑
            return;
        }
        try {
            Uri[] results = null;
            String dataString = data.getDataString();
            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
                ClipData clipData = data.getClipData();
                if (clipData != null) {
                    results = new Uri[clipData.getItemCount()];
                    for (int i = 0; i < clipData.getItemCount(); i++) {
                        ClipData.Item item = clipData.getItemAt(i);
                        results[i] = item.getUri();
                    }
                }
            }

            if (dataString != null) {
                results = new Uri[]{Uri.parse(dataString)};
                valueCallback.onReceiveValue(results);
            }else {
                valueCallback.onReceiveValue(null);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        valueCallback = null;
    }
    private void clearHistory(String url){
        String curUrl ="";
        String localUrl ="";
        int index = url.indexOf("?");
        if (index>0){
            curUrl = url.substring(0,index);
        }
        int i = mWebUrl.indexOf("?");
        if (i>0){
            localUrl = mWebUrl.substring(0,i);
        }
        if (!StringUtils.isEmpty(localUrl)&& !StringUtils.isEmpty(curUrl) && localUrl.contains(curUrl) && !url.toLowerCase().contains(payssion)){
            mWebview.clearHistory();
            isPayRedirectUrl = false;
        }
    }
    private void getOpenLink() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            mWebview.evaluateJavascript("javascript:(function() { return server.content; })();", new ValueCallback<String>() {
                @Override
                public void onReceiveValue(String s) {
                    TGLog.i(TAG, "evaluateJavascript:" + s);
                    SignPay signPay = JSON.parseObject(s, SignPay.class);
                    if (signPay!=null&&signPay.errcode == 0) {
                        if (!TextUtils.isEmpty(signPay.openlink)){
                            if (signPay.openlink.contains(alipayUrl)){
                                if (AppUtil.checkAliPayInstalled(getBaseContext())){
                                    Toast.makeText(getBaseContext(), R.string.uninstall_alipay, Toast.LENGTH_LONG).show();
                                }else {
                                    payAction(signPay.openlink);
                                }
                            }
                            if (signPay.openlink.contains(weipayUrl)){
                                if (!AppUtil.checkWeiXinInstalled(getBaseContext())){
                                    Toast.makeText(getBaseContext(), R.string.uninstall_wechat, Toast.LENGTH_LONG).show();
                                }else {
                                    payAction(signPay.openlink);
                                }
                            }
                                mWebview.goBack();
                            }

                    }
                    //将button显示的文字改成JS返回的字符串

                }
            });
        }

    }

    private void payAction(String url) {
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_VIEW);
        intent.setData(Uri.parse(url));
        startActivityForResult(intent, 100);
    }

    private class SimService {
        Activity activity;

        public SimService(Activity activity) {
            this.activity = activity;
        }

        @JavascriptInterface
        public void jumpAddDevice() {
            if (!activity.isFinishing()) {
                activity.finish();
            }
        }
        @JavascriptInterface
        public void jumpDeviceList() {
            TGLog.i(TAG, "jumpDeviceList");
            if (!activity.isFinishing()) {

                Intent i= new Intent();
                i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
                i.setClass(getBaseContext(), DeviceListActivity.class);
                activity.startActivity(i);
                activity.finish();
            }
        }
        @JavascriptInterface
        public String jsCallFunc(String params){
            TGLog.i(TAG, "params = " + params);
            if (StringUtils.isEmpty(params)){
                return null;
            }

            JSONObject object = JSONObject.parseObject(params);
            if (object == null){
                return null;
            }

            String func = object.getString("funcName");
            if (StringUtils.isEmpty(func)){
                return null;
            }
            String callback = object.getString("callback");
            String param = object.getString("param");
            return jsCallFuncImpl(func, callback, param);
        }

        private String jsCallFuncImpl(String func, String callback, String param){
            TGLog.i(TAG, "func" + func + ", param = " + param);
            if (StringUtils.equalsIgnoreCase(JsCallFunName.funcImplemented, func)){
                boolean isFun = JsCallFunName.isJsFun(param);
                return isFun? "1" : "0";
            }
            if (StringUtils.equalsIgnoreCase(JsCallFunName.openWebview, func)){
                mainHandler.post(() -> {
                    JSONObject jsonObject = JSONObject.parseObject(param);
                    boolean show = jsonObject.getBoolean("visible");
                    String url = jsonObject.getString("url");
                    ActivityHelper.showWebPopWindow(activity, show, url);
                });

            }
            else if (StringUtils.equalsIgnoreCase(JsCallFunName.setBackButton, func)){
                mainHandler.post(() -> {
                    JSONObject jsonObject = JSONObject.parseObject(param);
                    boolean show = jsonObject.getBoolean("visible");
                    ActivityHelper.setBackButton(activity, show);
                });

            }
            else if (JsCallFunName.unregistration.equals(func)){
                mainHandler.post(() -> {
                    if (!activity.isFinishing()){
                        activity.finish();
                        PreferenceUtil.setBoolean(getBaseContext(), CommonConstants.PRE_AUTO_LOGIN, false);
                        PreferenceUtil.setBoolean(getBaseContext(), CommonConstants.PRE_AUTO_WECHAT_LOGIN, false);
                        PreferenceUtil.setString(getBaseContext(), CommonConstants.PRE_USER_PWD, "");
                        PreferenceUtil.setString(getBaseContext(), CommonConstants.PRE_USER_NAME, "");
                        TGLog.d(TGLog.TAG, "jsCallFuncImpl");
                        ActivityHelper.startLoginActivity(WebBaseActivity.this, LoginHelper.TYPE_LOGOUT);
                    }
                });
            }else if (JsCallFunName.setTitle.equalsIgnoreCase(func)){
                mainHandler.post(() -> {
                    if (tvTitle!=null&&!TextUtils.isEmpty(param) && !StringUtils.equals(param, "Privacy strategy")) {
                        tvTitle.setText(param);
                        hasJsSetTitle = true;
                    }
                });


            }else if (JsCallFunName.wxShare.equals(func)){
                TGLog.d(TAG,"wxShare param = " +  param);

            }else if (JsCallFunName.getUserInfo.equals(func)){
                DeviceInfo info = new DeviceInfo();
                info.systemVersion =  String.format("Android %s", GetSystemMsgUtil.getSystemVersion());;
                info.model = String.format("%s %s", GetSystemMsgUtil.getDeviceBrand(),GetSystemMsgUtil.getSystemModel());
                String data = JSON.toJSONString(info);
                TGLog.i(TAG, "getUserInfo = " + data);
                return data;
            }else if (JsCallFunName.deviceReset.equals(func)){
                activity.runOnUiThread(() -> {
                    Intent  intent = new Intent();
                    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
                    intent.setClass(getBaseContext(), ResetDeviceActivity.class);
                    if (info!=null){
                        ActivityHelper.jump2ResetDeviceActivity(getBaseContext(), info.uuid, intent);
                    }
                });

            } else if (JsCallFunName.shareText.equals(func)){ // 分享纯文本
                activity.runOnUiThread(() -> {
                    JSONObject shareJson = null;
                    try {
                        shareJson = JSONObject.parseObject(param);
                    } catch (Throwable exJson) {
                        return;
                    }

                    if (shareJson == null){
                        return;
                    }

                    final String shareTitle = shareJson.containsKey("title") ? shareJson.getString("title") : "";
                    final String shareText = shareJson.containsKey("text") ? shareJson.getString("text") : "";

                    if (!TextUtils.isEmpty(shareText)) {
                        final Intent sendIntent = new Intent();
                        sendIntent.setAction(Intent.ACTION_SEND);
                        if (!TextUtils.isEmpty(shareTitle)) {
                            sendIntent.putExtra(Intent.EXTRA_TITLE, shareTitle);
                        }
                        sendIntent.putExtra(Intent.EXTRA_TEXT, shareText);
                        sendIntent.setType("text/plain");
                        Intent shareIntent = Intent.createChooser(sendIntent, null);
                        activity.startActivity(shareIntent);
                    }
                });
            } else if (JsCallFunName.updateStatusBarColor.equalsIgnoreCase(func)){
                activity.runOnUiThread(() -> {
                    if (!TextUtils.isEmpty(param)) {
                        updateStatusBarColor(param);
                    }
                });
            } else if (JsCallFunName.updateStatusBarTextColor.equalsIgnoreCase(func)){
                activity.runOnUiThread(() -> updateStatusBarTextColor("true".equals(param)));
            } else if (JsCallFunName.updateToolBarBackgroundColor.equalsIgnoreCase(func)){
                activity.runOnUiThread(() -> {
                    if (!TextUtils.isEmpty(param)) {
                        updateToolBarBackgroundColor(param);
                    }
                });
            } else if (JsCallFunName.updateToolBarTextColor.equalsIgnoreCase(func)){
                activity.runOnUiThread(() -> {
                    if (!TextUtils.isEmpty(param)) {
                        updateToolBarTextColor(param);
                    }
                });
            } else if (JsCallFunName.updateBackBtnColor.equalsIgnoreCase(func)){
                activity.runOnUiThread(() -> updateBackBtnColor("true".equals(param)));
            } else if (JsCallFunName.setContentFullScreen.equalsIgnoreCase(func)){
                activity.runOnUiThread(() -> setContentFullScreen("true".equals(param)));
            } else if (JsCallFunName.closeWebview.equalsIgnoreCase(func)){
                activity.runOnUiThread(() -> {
                    activity.setResult(1);
                    activity.finish();
                });
            }
            return  null;
        }
    }

    private static class DeviceInfo {
        public  String systemVersion;
        public  String model;

        public DeviceInfo() {
        }
    }
    public static class SignPay {
        public int errcode;
        public String openlink;
        public SignPay() {

        }
    }
}
